<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="代表姓名" prop="representativeName">
        <el-input
          v-model="queryParams.representativeName"
          placeholder="请输入代表姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="活动标题" prop="title">
        <el-input
          v-model="queryParams.title"
          placeholder="请输入活动的标题"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['RepresentativePerformance:RepresentativePerformance:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['RepresentativePerformance:RepresentativePerformance:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['RepresentativePerformance:RepresentativePerformance:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['RepresentativePerformance:RepresentativePerformance:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="RepresentativePerformanceList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="唯一标识" align="center" prop="id" />-->
<!--      <el-table-column label="代表的唯一标识" align="center" prop="representativeId" />-->
      <el-table-column label="代表姓名" align="center" prop="representativeName" />
      <el-table-column label="联系方式" align="center" prop="contactInfo" />
      <el-table-column label="活动标题" align="center" prop="title" />
      <el-table-column label="活动描述" align="center" prop="description"   />
      <el-table-column label="活动开始日期" align="center" prop="startDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="活动结束日期" align="center" prop="endDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="活动地点" align="center" prop="location" />
<!--      <el-table-column label="上传的图片路径" align="center" prop="imagePath" width="100">-->
<!--        <template slot-scope="scope">-->
<!--          <image-preview :src="scope.row.imagePath" :width="50" :height="50"/>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="图片描述" align="center" prop="logDescription" />-->
      <el-table-column label="纪实日期" align="center" prop="logDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.logDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center" prop="reviewStatus" />
      <el-table-column label="审核人" align="center" prop="reviewerId" />
      <el-table-column label="审核意见" align="center" prop="reviewComments" />
      <el-table-column label="审核时间" align="center" prop="reviewedAt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.reviewedAt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
<!--      <el-table-column label="发布状态" align="center" prop="publicationStatus" />-->
<!--      <el-table-column label="发布时间" align="center" prop="publishedAt" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.publishedAt, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="预留整数字段" align="center" prop="reservedInt" />-->
<!--      <el-table-column label="预留字符串字段" align="center" prop="reservedVarchar" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['RepresentativePerformance:RepresentativePerformance:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['RepresentativePerformance:RepresentativePerformance:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改代履职综合对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
<!--        <el-form-item label="代表的唯一标识" prop="representativeId">-->
<!--          <el-input v-model="form.representativeId" placeholder="请输入代表的唯一标识" />-->
<!--        </el-form-item>-->
        <el-form-item label="代表姓名" prop="representativeName">
          <el-input v-model="form.representativeName" placeholder="请输入代表姓名" />
        </el-form-item>
        <el-form-item label="联系方式" prop="contactInfo">
          <el-input v-model="form.contactInfo" placeholder="请输入联系方式" />
        </el-form-item>
        <el-form-item label="履职活动的标题" prop="title">
          <el-input v-model="form.title" placeholder="请输入活动标题" />
        </el-form-item>
        <el-form-item label="活动描述" prop="description">
          <el-input v-model="form.description" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="活动开始日期" prop="startDate">
          <el-date-picker clearable
            v-model="form.startDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择活动开始日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="活动结束日期" prop="endDate">
          <el-date-picker clearable
            v-model="form.endDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择活动结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="活动地点" prop="location">
          <el-input v-model="form.location" placeholder="请输入活动地点" />
        </el-form-item>
        <el-form-item label="上传的图片路径" prop="imagePath">
          <image-upload v-model="form.imagePath"/>
        </el-form-item>
        <el-form-item label="图片描述" prop="logDescription">
          <el-input v-model="form.logDescription" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="纪实日期" prop="logDate">
          <el-date-picker clearable
            v-model="form.logDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择纪实日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="审核状态" prop="reviewStatus">
          <el-select v-model="form.reviewStatus" placeholder="请选择状态">
            <el-option label="待审批"  value="待审批"> </el-option>
            <el-option label="通过"  value="通过"> </el-option>
            <el-option label="驳回"  value="驳回"> </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="审核人" prop="reviewerId">
          <el-input v-model="form.reviewerId" placeholder="请输入审核人ID" />
        </el-form-item>
        <el-form-item label="审核意见" prop="reviewComments">
          <el-input v-model="form.reviewComments" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="审核时间" prop="reviewedAt">
          <el-date-picker clearable
            v-model="form.reviewedAt"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择审核时间">
          </el-date-picker>
        </el-form-item>
<!--        <el-form-item label="发布状态" prop="publicationStatus">-->
<!--          <el-input v-model="form.publicationStatus" placeholder="请输入发布状态" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="发布时间" prop="publishedAt">-->
<!--          <el-date-picker clearable-->
<!--            v-model="form.publishedAt"-->
<!--            type="date"-->
<!--            value-format="yyyy-MM-dd"-->
<!--            placeholder="请选择发布时间">-->
<!--          </el-date-picker>-->
<!--        </el-form-item>-->
        <el-form-item label="预留整数字段" prop="reservedInt">
          <el-input v-model="form.reservedInt" placeholder="请输入预留整数字段" />
        </el-form-item>
        <el-form-item label="预留字符串字段" prop="reservedVarchar">
          <el-input v-model="form.reservedVarchar" placeholder="请输入预留字符串字段" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listRepresentativePerformance, getRepresentativePerformance, delRepresentativePerformance, addRepresentativePerformance, updateRepresentativePerformance } from "@/api/RepresentativePerformance/RepresentativePerformance";

export default {
  name: "RepresentativePerformance",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 代履职综合表格数据
      RepresentativePerformanceList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        representativeName: null,
        title: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询代履职综合列表 */
    getList() {
      this.loading = true;
      listRepresentativePerformance(this.queryParams).then(response => {
        this.RepresentativePerformanceList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        representativeId: null,
        representativeName: null,
        contactInfo: null,
        title: null,
        description: null,
        startDate: null,
        endDate: null,
        location: null,
        imagePath: null,
        logDescription: null,
        logDate: null,
        reviewStatus: null,
        reviewerId: null,
        reviewComments: null,
        reviewedAt: null,
        publicationStatus: null,
        publishedAt: null,
        reservedInt: null,
        reservedVarchar: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加代履职综合";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getRepresentativePerformance(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改代履职综合";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateRepresentativePerformance(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRepresentativePerformance(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除代履职综合编号为"' + ids + '"的数据项？').then(function() {
        return delRepresentativePerformance(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('RepresentativePerformance/RepresentativePerformance/export', {
        ...this.queryParams
      }, `RepresentativePerformance_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
